package com.qf.mybatisplus.rabbitMQ;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;


/**
* @Description work模型消费者
* @Param
* @Author 12136
* @Date 13:49 2021/11/24
* @return
**/
//@Component
public class WorkConsumer {

    @RabbitListener(queuesToDeclare = @Queue(name = "work",durable = "true"))
    public void getMessage(String msg, Channel channel, Message message) throws Exception {
        TimeUnit.SECONDS.sleep(1);
        System.err.println("消费者1收到: "+msg);
        // 手动  ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }


    @RabbitListener(queuesToDeclare = @Queue(name = "work",durable = "true"))
    public void getMessage2(String msg, Channel channel, Message message) throws Exception{
        TimeUnit.SECONDS.sleep(1);
        System.err.println("消费者2收到: "+msg);
        // 手动  ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }


}